﻿<UserControl x:Class="SEToolbox.Views.ControlVoxel"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:controls="clr-namespace:SEToolbox.Controls"
             xmlns:converters="clr-namespace:SEToolbox.Converters"
             xmlns:props="clr-namespace:SEToolbox.Properties"
             xmlns:views="clr-namespace:SEToolbox.Views"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <converters:ResouceToImageConverter x:Key="ResouceToImageConverter"/>
        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
        <Style TargetType="ListViewItem">
            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        </Style>
        <TextBlock x:Shared="False" x:Key="DisplayBlock" Text="{Binding DisplayName}" />
    </UserControl.Resources>
    <Grid>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <Label Grid.ColumnSpan="2">Asteroid</Label>
            <Menu Grid.Column="0" Grid.Row="1" Grid.ColumnSpan="2" DockPanel.Dock="Top">
                <Menu.ItemsPanel>
                    <ItemsPanelTemplate>
                        <DockPanel HorizontalAlignment="Stretch" Height="22"/>
                    </ItemsPanelTemplate>
                </Menu.ItemsPanel>
                <MenuItem Header="Ore/Material">
                    <!--<MenuItem Header="Re-seed Ore" Command="{Binding ReseedCommand}" />-->
                    <MenuItem Header="Replace All Material" ItemsSource="{Binding GameMaterialList}">
                        <MenuItem.ItemContainerStyle>
                            <Style TargetType="MenuItem">
                                <Setter Property="Header" Value="{StaticResource DisplayBlock}"/>
                                <Setter Property="Command" Value="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=MenuItem}, Path=DataContext.ReplaceAllCommand}" />
                                <Setter Property="CommandParameter" Value="{Binding MaterialName}" />
                            </Style>
                        </MenuItem.ItemContainerStyle>
                    </MenuItem>
                    <MenuItem Header="Replace surface Material" ItemsSource="{Binding GameMaterialList}">
                        <MenuItem.ItemContainerStyle>
                            <Style TargetType="MenuItem">
                                <Setter Property="Header" Value="{StaticResource DisplayBlock}"/>
                                <Setter Property="Command" Value="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=MenuItem}, Path=DataContext.ReplaceSurfaceCommand}" />
                                <Setter Property="CommandParameter" Value="{Binding MaterialName}" />
                            </Style>
                        </MenuItem.ItemContainerStyle>
                    </MenuItem>
                    <MenuItem Header="Replace Selected Material" Command="{Binding ReplaceSelectedMenuCommand}" ItemsSource="{Binding EditMaterialList}">
                        <MenuItem.ItemContainerStyle>
                            <Style TargetType="MenuItem">
                                <Setter Property="Header" Value="{StaticResource DisplayBlock}"/>
                                <Setter Property="Command" Value="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=MenuItem}, Path=DataContext.ReplaceSelectedCommand}" />
                                <Setter Property="CommandParameter" Value="{Binding MaterialName}" />
                            </Style>
                        </MenuItem.ItemContainerStyle>
                    </MenuItem>
                </MenuItem>
                <MenuItem Header="Slice">
                    <MenuItem Header="Slice quarter (to copy)" Command="{Binding SliceQuarterCommand}" ToolTip="Removes a quarter from the direction of the sun." />
                    <MenuItem Header="Slice half (to copy)" Command="{Binding SliceHalfCommand}"  ToolTip="Removes a half from the direction of the sun."  />
                </MenuItem>
                <MenuItem Header="Extract">
                    <MenuItem Header="Station intersection loose" Command="{Binding ExtractStationIntersectLooseCommand}" ToolTip="Any asteroid cell that intersects a station cube gets removed. This will lead to small narrow gaps between the asteroid and station surfaces." />
                    <!--<MenuItem Header="Station intersection tight" Command="{Binding ExtractStationIntersectTightCommand}" ToolTip="Any asteroid cell that is completely enclosed by any number of station cubes get removed. This results in the asteroid overlapping the faces of the station, leaving no gaps." />-->
                </MenuItem>
                <MenuItem Header="Rotate" Style="{StaticResource ToolBarTopMenuitem}">
                    <MenuItem.Icon>
                        <Image Width="16" Height="16" Source="{Binding Converter={StaticResource ResouceToImageConverter}, ConverterParameter=replace2}" />
                    </MenuItem.Icon>
                    <MenuItem Header="Rotate asteroid backward-down around X axis (+90 Pitch)" Command="{Binding RotateAsteroidPitchPositiveCommand}"/>
                    <MenuItem Header="Rotate asteroid forward-down around X axis (-90 Pitch)" Command="{Binding RotateAsteroidPitchNegativeCommand}"/>
                    <MenuItem Header="Rotate asteroid anti-clockwise around Y axis (+90 Yaw)" Command="{Binding RotateAsteroidYawPositiveCommand}"/>
                    <MenuItem Header="Rotate asteroid clockwise around Y axis (-90 Yaw)" Command="{Binding RotateAsteroidYawNegativeCommand}"/>
                    <MenuItem Header="Rotate asteroid left-down around Z axis (+90 Roll)" Command="{Binding RotateAsteroidRollPositiveCommand}"/>
                    <MenuItem Header="Rotate asteroid right-down around Z axis (-90 Roll)" Command="{Binding RotateAsteroidRollNegativeCommand}"/>
                </MenuItem>
                <MenuItem HorizontalAlignment="Right" Style="{StaticResource ToolBarTopMenuitem}" ToolTip="Copy text detail to Clipboard" Command="{Binding CopyDetailCommand}">
                    <MenuItem.Icon>
                        <Image Width="16" Height="16" Source="{Binding Converter={StaticResource ResouceToImageConverter}, ConverterParameter=copy}" />
                    </MenuItem.Icon>
                </MenuItem>
            </Menu>
            <Label Grid.Row="2" Grid.Column="0" Content="Position:"/>
            <views:ControlPosition Grid.Row="2" Grid.Column="1"/>
            <Separator Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2"/>

            <TextBlock Grid.Row="4" Grid.Column="0" Margin="4 0 4 0" Text="Name:"/>
            <TextBlock Grid.Row="4" Grid.Column="1" VerticalAlignment="Center" Text="{Binding Name}"/>
            <TextBlock Grid.Row="5" Grid.Column="0" Margin="4 0 4 0" Text="Bounding Size:"/>
            <TextBlock Grid.Row="5" Grid.Column="1" VerticalAlignment="Center">
                <TextBlock.Text>
                    <MultiBinding StringFormat="{}{0} × {1} × {2} blocks">
                        <Binding Path="Size.Width" />
                        <Binding Path="Size.Height" />
                        <Binding Path="Size.Depth" />
                    </MultiBinding>
                </TextBlock.Text>
            </TextBlock>
            <TextBlock Grid.Row="6" Grid.Column="0" Margin="4 0 4 0" Text="Size:"/>
            <TextBlock Grid.Row="6" Grid.Column="1" VerticalAlignment="Center">
                <TextBlock.Text>
                    <MultiBinding StringFormat="{}{0}m × {1}m × {2}m">
                        <Binding Path="ContentSize.Width" />
                        <Binding Path="ContentSize.Height" />
                        <Binding Path="ContentSize.Depth" />
                    </MultiBinding>
                </TextBlock.Text>
            </TextBlock>
            <TextBlock Grid.Row="7" Grid.Column="0" Margin="4 0 4 0" Text="Center:"/>
            <TextBlock Grid.Row="7" Grid.Column="1" VerticalAlignment="Center">
                <TextBlock.Text>
                    <MultiBinding StringFormat="{}{0:#,##0.0000}, {1:#,##0.0000}, {2:#,##0.0000}">
                        <Binding Path="Center.X" />
                        <Binding Path="Center.Y" />
                        <Binding Path="Center.Z" />
                    </MultiBinding>
                </TextBlock.Text>
            </TextBlock>
            <TextBlock Grid.Row="8" Grid.Column="0" Margin="4 0 4 0" Text="Volume:"/>
            <TextBlock Grid.Row="8" Grid.Column="1" VerticalAlignment="Center" Text="{Binding Volume, StringFormat='{}{0:#,##0.00}m³'}" />
            <TextBlock Grid.Row="9" Grid.Column="0" Margin="4 0 4 0" Text="VoxCells:"/>
            <TextBlock Grid.Row="9" Grid.Column="1" VerticalAlignment="Center" Text="{Binding VoxCells, StringFormat='{}{0:#,##0}'}" />
            <TextBlock Grid.Row="10" Grid.Column="0" Margin="4 0 4 0" Text="Distance:"/>
            <TextBlock Grid.Row="10" Grid.Column="1" VerticalAlignment="Center" Text="{Binding PlayerDistance, StringFormat='{}{0:#,###0.0} m'}" />

            <controls:SortableListView Grid.Row="11" Grid.Column="0" Grid.ColumnSpan="2" ItemsSource="{Binding MaterialAssets, Mode=OneWay}" SelectedValue="{Binding SelectedMaterialAsset}"
                ColumnHeaderArrowUpTemplate="{StaticResource HeaderTemplateArrowUp}" ColumnHeaderArrowDownTemplate="{StaticResource HeaderTemplateArrowDown}">
                <ListView.View>
                    <GridView>
                        <GridViewColumn Header="Material" DisplayMemberBinding="{Binding MaterialName}" Width="95"/>
                        <controls:SortableGridViewColumn Header="Volume" Width="100" SortBinding="{Binding Volume}">
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock TextAlignment="Right" Text="{Binding Path=Volume, StringFormat='{}{0:#,##0.00} m³'}" />
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </controls:SortableGridViewColumn>
                        <controls:SortableGridViewColumn Header="Percent" SortBinding="{Binding Percent}">
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock TextAlignment="Right" Text="{Binding Path=Percent, StringFormat='{}{0:P2}'}" />
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </controls:SortableGridViewColumn>
                    </GridView>
                </ListView.View>
                <ListBox.ContextMenu>
                    <ContextMenu>
                        <MenuItem Header="Replace Material" Command="{Binding ReplaceSelectedMenuCommand}" ItemsSource="{Binding EditMaterialList}">
                            <MenuItem.ItemContainerStyle>
                                <Style TargetType="MenuItem">
                                    <Setter Property="Header" Value="{StaticResource DisplayBlock}"/>
                                    <Setter Property="Command" Value="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=MenuItem}, Path=DataContext.ReplaceSelectedCommand}" />
                                    <Setter Property="CommandParameter" Value="{Binding MaterialName}" />
                                </Style>
                            </MenuItem.ItemContainerStyle>
                        </MenuItem>
                    </ContextMenu>
                </ListBox.ContextMenu>
            </controls:SortableListView>
            <controls:BusyIndicator Grid.Row="11" Grid.Column="0" Grid.ColumnSpan="2" Visibility="{Binding IsBusy, Converter={StaticResource BooleanToVisibilityConverter}}" />
        </Grid>
    </Grid>
</UserControl>
